package sinoservices.demo.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.web.bind.annotation.*;
import sinoservices.demo.entity.Userinfo;
import sinoservices.demo.mapper.UserinfoMapper;
import sinoservices.demo.service.UserinfoService;

import java.util.List;

@RestController
@RequestMapping("/testBoot")
public class UserinfoController {
    @Autowired
    private UserinfoService userinfoService;

    @RequestMapping(value = "/saveUser",method = RequestMethod.POST)
    public Userinfo saveUser(@RequestBody Userinfo userinfo){

        return userinfoService.saveUser(userinfo);
    }

    @RequestMapping(value = "/delUser",method = RequestMethod.GET)
    public String deleteUser(int id){
        int result = userinfoService.deleteUserById(id);
        if (result >= 1){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @RequestMapping(value = "updateUser",method = RequestMethod.POST)
    public String update(@RequestBody Userinfo userinfo) {
        int result = userinfoService.updateUser(userinfo);
        if (result >= 1) {
            return "修改成功";
        } else {
            return "修改失败";
        }
    }

    @RequestMapping(value = "getUser/{id}",method = RequestMethod.GET)
    public String getUserInfo(@PathVariable int id){
        return userinfoService.getUserInfo(id).toString();
    }

    @RequestMapping("/selectAllUser")
    @ResponseBody
    public List<Userinfo> ListUser() {
        return userinfoService.selectAllUser();
    }
}
